﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CustomControl
{
    /// <summary>
    /// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file.
    ///
    /// Step 1a) Using this custom control in a XAML file that exists in the current project.
    /// Add this XmlNamespace attribute to the root element of the markup file where it is 
    /// to be used:
    ///
    ///     xmlns:MyNamespace="clr-namespace:IndleveringControl"
    ///
    ///
    /// Step 1b) Using this custom control in a XAML file that exists in a different project.
    /// Add this XmlNamespace attribute to the root element of the markup file where it is 
    /// to be used:
    ///
    ///     xmlns:MyNamespace="clr-namespace:IndleveringControl;assembly=IndleveringControl"
    ///
    /// You will also need to add a project reference from the project where the XAML file lives
    /// to this project and Rebuild to avoid compilation errors:
    ///
    ///     Right click on the target project in the Solution Explorer and
    ///     "Add Reference"->"Projects"->[Select this project]
    ///
    ///
    /// Step 2)
    /// Go ahead and use your control in the XAML file.
    ///
    ///     <MyNamespace:CustomControl1/>
    ///
    /// </summary>
    public class CustomControl : Control
    {
        private string name;
        private int bøjlenr;

        static CustomControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl), new FrameworkPropertyMetadata(typeof(CustomControl)));
        }

        public CustomControl(RoutedEventHandler e, string name, int bøjlenr)
        {
            this.setButton(e, name, bøjlenr);
            this.name = name;
            this.bøjlenr = bøjlenr;
        }

        public string GuestName
        {
            get { return name; }
        }

        public int Bøjlenr
        {
            get { return bøjlenr; }
        }

        public string Header
        {
            get
            {
                return (string)GetValue(HeaderProperty);
            }
            set
            {
                SetValue(HeaderProperty, value);
            }
        }

        public static readonly DependencyProperty HeaderProperty =
          DependencyProperty.Register("Header", typeof(string),
          typeof(CustomControl), new UIPropertyMetadata());

        private object Content
        {
            get
            {
                return (object)GetValue(ContentProperty);
            }
            set
            {
                SetValue(ContentProperty, value);
            }
        }

        private void setButton(RoutedEventHandler e, string name, int bøjlenr)
        {
            StackPanel stkpnlInBtn = new StackPanel();
            
            Label lblName = new Label();
            lblName.Content = name;
            lblName.FontSize = 50;
            lblName.Width = 600;
            lblName.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
            
            Label lblHangerNo = new Label();
            lblHangerNo.Content = bøjlenr;
            lblHangerNo.FontSize = 80;
            lblHangerNo.FontWeight = FontWeights.Bold;
            lblHangerNo.Width = 300;
            lblHangerNo.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;

            stkpnlInBtn.Children.Add(lblName);
            stkpnlInBtn.Children.Add(lblHangerNo);
            stkpnlInBtn.Background = new SolidColorBrush(Color.FromRgb(225, 225, 204));
            stkpnlInBtn.Width = 600;
            stkpnlInBtn.Height = 370;
            
            Button btn = new Button();
            btn.Click += e;
            btn.Background = new SolidColorBrush(Color.FromRgb(255, 255, 204));
            btn.Content = stkpnlInBtn;
            btn.BorderThickness = new Thickness(0,0,0,0);
            btn.Tag = this;
            this.Content = btn;
        }
        
        
        public static readonly DependencyProperty ContentProperty =
          DependencyProperty.Register("Content", typeof(object),
          typeof(CustomControl), new UIPropertyMetadata());

        public SolidColorBrush HeaderBackground
        {
            get
            {
                return (SolidColorBrush)GetValue(HeaderBackgroundProperty);
            }
            set
            {
                SetValue(HeaderBackgroundProperty, value);
            }
        }

        public static readonly DependencyProperty HeaderBackgroundProperty =
          DependencyProperty.Register("HeaderBackground", typeof(SolidColorBrush),
          typeof(CustomControl), new UIPropertyMetadata());
    }
}
